package com.sunda.spmscommon.service.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sunda.spmscommon.entity.SysLogMq;
import com.sunda.spmscommon.mapper.SysLogMqMapper;
import com.sunda.spmscommon.service.ISysLogMqService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * <p>
 * MQ系统日志表 服务实现类
 * </p>
 *
 * @author Wayne
 * @since 2021-05-27
 */
@Service
public class SysLogMqServiceImpl extends ServiceImpl<SysLogMqMapper, SysLogMq> implements ISysLogMqService {

    @Override
    public void addSysLogMq(String logType, String requestInterface, String requestDesc, String functionId, String requestParam, String receivedMessage, String remarks) {
        SysLogMq sysLogMq = new SysLogMq();
        String uuid = UUID.randomUUID().toString().replaceAll("-", "").toLowerCase();
        sysLogMq.setUuid(uuid);
        sysLogMq.setLogType(logType);
        sysLogMq.setRequestInterface(requestInterface);
        sysLogMq.setRequestDesc(requestDesc);
        sysLogMq.setFunctionId(functionId);
        sysLogMq.setRequestParam(requestParam);
        sysLogMq.setReceivedMessage(receivedMessage);
        sysLogMq.setRemarks(remarks);
        sysLogMq.setUserId("mq system");
        this.baseMapper.insert(sysLogMq);
    }

    @Override
    public List<Map<String, Object>> getSysLogMq(String logType) {
        logType = StringUtils.isNotEmpty(logType) ? logType : null;
        return this.baseMapper.getSysLogMq(logType);
    }
}
